#include "LevelItem.h"
#include "../util.h"
#include "../Persistence.h"
using namespace suta;

bool LevelItem::init(int level,bool enabled)
{
	bool ret=false;
	do 
	{
		CC_BREAK_IF(!CCLayer::init());

		m_iLevel=level;
		setContentSize(CCSizeMake(100,100));
		setIsRelativeAnchorPoint(true);
		setIsTouchEnabled(enabled);
		{
			//bg
			CCSprite*bg=CCSprite::spriteWithFile(enabled?"level_item.png":"level_item_disabled.png");
			bg->setPosition(ccp(50,50));
			addChild(bg);
		}
		{
			char str[5]={0};
			SPRINTF(str,5,"%d",m_iLevel+1);
			CCLabelBMFont*font=CCLabelBMFont::labelWithString(str,"fnt/level_item.fnt");
			font->setPosition(ccp(50,50));
			addChild(font);
		}
		{
			int stars=Persistence::shardPersiatence()->getLevelStarCnt(m_iLevel);
			for (int i=0;i<stars;i++)
			{
				CCSprite *star=CCSprite::spriteWithTexture(CCTextureCache::sharedTextureCache()->addImage("star.png"));
				star->setPosition(ccp(15+i*15,15));
				addChild(star);
			}
		}

		ret=true;
	} while (0);
	return ret;
}